<include file="Public:header_new" />
<style>
	body {background:#283046;}
</style>
<link rel="stylesheet" href="__PUBLIC__/Home/ecshe_css/exchange.css">
<style>
	.copy_button{float:right;margin-top:5px;margin-right:10px;padding:0 10px;height:30px;}
</style>

<div class="C2C_mian_box">
	<div class="column">
		<a href="{:U('Exchange/index')}"><h2 style="text-transform:uppercase;">{:Anchor_CNY} {:L('交易')}</h2></a>
		<div class="navs">
			<a href="{:U('Exchange/bank')}">&#8226; {:L('银行卡管理')}</a>
		</div>
	</div>

	<div class="clear">
		<p style="margin-top:20px;margin-bottom: 20px;padding:20px;font-size:16px;color: #ffffff;background-color: #283046;border-radius:8px;">
			{$configs['mycz_prompt']}
		</p>
		<div class="buy-box">
			<p class="buy-title">{:L('付款期限')} : <span>30</span> {:L('分钟')}</p>
			<input type="text" name="price" id="buy_price" autocomplete="off" class="prohibit" value="1.00" readonly />
			<input type="text" name="num" id="buy_num" autocomplete="off" maxlength="11" />
			<p class="buy-count">
				<span>{:L('交易额')}<b id="buy_mum">0.00</b> CNY</span>
				<span></span>
			</p>
			<label class="chain-name1">{:L('买入价')}（￥）</label>
			<label class="chain-name2" style="text-transform:uppercase;">{:L('买入量')}（{:Anchor_CNY}）</label>
			<button type="button" class="btn-buy" id="buybutton" onclick="tradeadd_buy();">{:L('立即买入')}</button>
		</div>

		<div class="buy-box sell-box">
			<p class="buy-title" style="text-transform:uppercase;">{:L('可用')} {:Anchor_CNY}<span>{$cny['ky']}</span></p>
			<input type="text" name="price" id="sell_price" autocomplete="off" class="prohibit" value="0.99" readonly />
			<input type="text" name="num" id="sell_num" autocomplete="off" maxlength="11" />
			<p class="buy-count">
				<span>{:L('交易额')}<b id="sell_mum">0.00</b> CNY</span>
				<span></span>
			</p>
			<label class="chain-name1">{:L('卖出价')}（￥）</label>
			<label class="chain-name2" style="text-transform:uppercase;">{:L('卖出量')}（{:Anchor_CNY}）</label>
			<button type="button" class="btn-buy" id="sellerbutton" onclick="tradeadd_sell();">{:L('立即卖出')}</button>
		</div>
	</div>
</div>

<div class="C2C_hint">
	<h3 class="title">{:L('温馨提示')}</h3>
	<p>为了您的购买可以快速到账，请在交易前仔细阅读以下注意事项：</p>
	<p>1. 买卖商户均为实名认证商户，并提供保证金，可放心交易；</p>
	<p>2. 如需申请成为商户请发邮件到 <b style="color:#FF8702">{$configs['contact']}</b> ；</p>
	<p>3. 请使用本人绑定的银行卡进行汇款，其他任何方式汇款都会退款。（禁止微信和支付宝）</p>
	<p>4. 商家处理时间 <b style="color:#097DF7">9:00 - 21:00</b> 非处理时间的订单会在第二天 <b style="color:#097DF7">9:00</b> 开始处理，一般接单后24小时内会完成打款。</p>
	<p>5. 单天最多只能发起 <b style="color:#097DF7">10</b> 笔卖出订单。</p>
	<p>6. 单笔充值限额 {$configs['mycz_min']} CNY ~ {$configs['mycz_max']} CNY<span style="margin: 0 15px;">|</span>单笔提现限额 {$configs['mytx_min']} CNY ~ {$configs['mytx_max']} CNY</p>
</div>

<div class="C2C_order_list">
	<ul class="table-head">
		<li style="width: 15%"><i></i>{:L('时间')}</li>
		<li style="width: 22%"><i></i>{:L('类别')}</li>
		<li style="width: 14%"><i></i>{:L('数量')}</li>
		<li style="width: 10%"><i></i>{:L('单价')}(￥)</li>
		<li style="width: 14%"><i></i>{:L('总价')}(￥)</li>
		<li style="width: 15%" class="tc">{:L('状态')}</li>
		<li style="width: 10%" class="tc">{:L('操作')}</li>
	</ul>
	<ul class="table-list">
		<volist name="list" id="vo">
			<li>
				<dl>
					<dd class="fl" style="width:15%"><i></i>{$vo.addtime|date='Y-m-d H:i:s',###}</dd>
					<dd class="fl otype" style="width:22%;text-transform:uppercase;"><i></i>
						<eq name="vo.otype" value="1">{:L('买入')} {:Anchor_CNY}/CNY</eq>
						<eq name="vo.otype" value="2">{:L('卖出')} {:Anchor_CNY}/CNY</eq>
						<br><i></i><b>{:L('流水号：')}{$vo.orderid}</b>
					</dd>
					<dd class="fl" style="width:14%"><i></i>{$vo.num}</dd>
					<dd class="fl" style="width:10%"><i></i>{$vo.uprice}</dd>
					<dd class="fl" style="width:14%"><i></i>{$vo.mum}</dd>
					<dd class="fl tc" style="width:15%">
						<eq name="vo.otype" value="1">
							<if condition="$vo.status eq 1"><span class="green icon_time">{:L('待支付')}</span>
							<elseif condition="$vo.status eq 2" /><span class="green icon_time">{:L('处理中')}</span>
							<elseif condition="$vo.status eq 3" /><span class="green icon_yhk">{:L('支付成功')}</span>
							<elseif condition="$vo.status eq 8" /><span class="red icon_yhkqx">{:L('已取消')}</span>
							<else />--</if>
						<else />
							<if condition="$vo.status eq 1"><span class="green icon_time">{:L('待处理')}</span>
							<elseif condition="$vo.status eq 2" /><span class="green icon_time">{:L('处理中')}</span>
							<elseif condition="$vo.status eq 3" /><span class="green icon_yhk">{:L('打款成功')}</span>
							<elseif condition="$vo.status eq 8" /><span class="red icon_yhkqx">{:L('已取消')}</span>
							<else />--</if>
						</eq>
					</dd>
					<dd class="fl tc" style="width:10%">
						<eq name="vo.otype" value="1">
							<eq name="vo.status" value="1">
								<a class="red" href="javascript:void(0)" onclick="addPayment({$vo['id']},{$vo['aid']})"><b>{:L('付款信息')}</b></a>
							</eq>
						</eq>
						<eq name="vo.otype" value="2">
							<eq name="vo.status" value="0"> -- </eq>
						</eq>
						<eq name="vo.status" value="2"> -- </eq>
						<eq name="vo.status" value="3"> -- </eq>
						<eq name="vo.status" value="8"> -- </eq>
					</dd>
				</dl>
			</li>
		</volist>
	</ul>
	<div class="pages">{$page}</div>
</div>

<div class="float_win_pay float_win_table" id="addPayment" style="display: none;">
    <div class="tan_title">
        <h4>{:L('汇款订单')}</h4>
        <span class="close-btn" onclick="closeCharge();">x</span>
    </div>
    <div class="payment_content">
    	<p>{:L('1.请按提示信息向该卖家汇款；')}</p>
		<div style="height:300px;">
			<table width="100%">
				<tbody id="payment"></tbody>
			</table>
		</div>
   		<p>{:L('2.转账时请一定要填写备注信息；')}</p>
   		<p>{:L('3.卖家确认收到款后，自动充值'.Anchor_CNY.'。如超过24小时未收到币，请向客服反馈解决。')}</p>
   		<p class="red">{:L('4.请务必使用本人绑定的银行卡通过手机银行或网银进行转账。')}</p>
   		<p class="red">{:L('5.请在30分钟之内完成转账，否则随时订单会被系统取消')}</p>
    </div>
</div>

<div class="float_win_bank" id="addidcard" style="display: none">
    <h2 class="tan_title">{:L('请先通过实名认证，再进行'.Anchor_CNY.'交易')}</h2>
    <div class="bank_content">
    	<a class="btn btn_1" href="{:U('User/index')}">{:L('去实名')}</a>
    	<a class="btn btn_2" href="#" onclick="closeCharge();">{:L('取消')}</a>
    </div>
</div>
<div class="float_win_bank" id="addBank" style="display: none">
    <h2 class="tan_title">{:L('银行卡未绑定，请前往绑定银行卡')}</h2>
    <div class="bank_content">
    	<a class="btn btn_1" href="{:U('Exchange/bank')}">{:L('去绑定')}</a>
    	<a class="btn btn_2" href="#" onclick="closeCharge();">{:L('取消')}</a>
    </div>
</div>
<div id="dialogBoxShadow" style="position: absolute; top: 0px; left: 0px; z-index: 100; background-color: rgb(0, 0, 0); opacity: 0.5; width: 100%; background-position: initial initial; background-repeat: initial initial; display: none;"></div>


<script type="text/javascript">
var trans_lock = 0;
	
$('#buy_num').bind('input propertychange', function () {
    $("#buy_mum").html((($('#buy_num').val() * $('#buy_price').val()).toFixed(8) * 1).toFixed(2));
});
$('#sell_num').bind('input propertychange', function () {
    $("#sell_mum").html((($('#sell_num').val() * $('#sell_price').val()).toFixed(8) * 1).toFixed(2));
});
	
function tradeadd_buy(){
	var idcard = "{$idcard}";
	var banks = "{$banks}";	
	var logins = "{$logins}";
	
	if(trans_lock){
		layer.msg("{:L('不要重复提交')}",{icon : 2 });
		return;
	}
	trans_lock = 1;
	
	if(logins == 0){
		layer.msg("{:L('请先登录！')}");
		trans_lock = 0;
		return false;
	}
	if(idcard == 0){
		addidcard();
		trans_lock = 0;
		return false;
	}
	if(banks == 0){
		addBank();
		trans_lock = 0;
		return false;
	}

	var price = parseFloat($('#buy_price').val());
	var num = parseFloat($('#buy_num').val());
	//var paypassword=$('#buy_paypassword').val();
	var reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
	
	if(price==""||price==null||!reg.test(price)){
		layer.tips("{:L('交易价格必须大于')}0",'#buy_price',{tips : 3 });
		trans_lock = 0;
		return false;
	}
	if(num==""||num==null||!reg.test(num)){
		layer.tips("{:L('交易数量必须大于')}0",'#buy_num',{tips : 3 });
		trans_lock = 0;
		return false;
	}

	layer.load(2);

	$.post("{:U('Exchange/upTrade')}",{price : $('#buy_price').val(),num : $('#buy_num').val(),otype : 1 },function(data){
		layer.closeAll('loading');
		trans_lock = 0;	
		if (data.status==1) {
			$("#buy_num").val('');
			$("#sell_num").val('');
			$("#buy_mum").html('0.00');
			$("#sell_mum").html('0.00');
			//$('#buy_paypassword').val('');
						
			layer.msg(data.info,{icon : 1 });
			setTimeout('addPayment('+data.url.id+','+data.url.aid+')', 2000); //延迟
			return false;
		} else {
			layer.msg(data.info,{icon : 2 });
			return false;
		}
	},'json');
}

function tradeadd_sell(){
	var idcard = "{$idcard}";
	var banks = "{$banks}";	
	var logins = "{$logins}";
	
	if(trans_lock){
		layer.msg("{:L('不要重复提交')}",{icon : 2 });
		return;
	}
	trans_lock = 1;
	
	if(logins == 0){
		layer.msg("{:L('请先登录！')}");
		trans_lock = 0;
		return false;
	}
	if(idcard == 0){
		addidcard();
		trans_lock = 0;
		return false;
	}
	if(banks == 0){
		addBank();
		trans_lock = 0;
		return false;
	}
	
	var price=parseFloat($('#sell_price').val());
	var num=parseFloat($('#sell_num').val());
	//var paypassword=$('#sell_paypassword').val();
	var reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
	
	if(price==""||price==null||!reg.test(price)){
		layer.tips("{:L('交易价格必须大于')}0",'#sell_price',{tips : 3 });
		trans_lock = 0;
		return false;
	}
	if(num==""||num==null||!reg.test(num)){
		layer.tips("{:L('交易数量必须大于')}0",'#sell_num',{tips : 3 });
		trans_lock = 0;
		return false;
	}

	layer.load(2);

	$.post("{:U('Exchange/upMytx')}",{price : $('#sell_price').val(),num : $('#sell_num').val(),otype : 2 },function(data){
		layer.closeAll('loading');
		trans_lock = 0;
		if (data.status==1) {
			$("#buy_num").val('');
			$("#sell_num").val('');
			$("#buy_mum").val('0.00');
			$("#sell_mum").val('0.00');
			//$('#buy_paypassword').val('');
			
			layer.msg(data.info,{icon : 1 });
			setTimeout('window.location.reload()', 3000); //延迟
			return false;
		} else {
			layer.msg(data.info,{icon : 2 });
			return false;
		}
	},'json');
}

function addPayment(id,aid) {
	if (id||aid) {
		var ids = id;
		var aids = aid;
	} else {
		var ids = 0;
		var aids = 0;		
	}
	
	$.post("/Ajax/c2cPayment?id="+ids+"&aid="+aids+"&ajax=json",function(data){
		var data = JSON.parse(data);
		if(data){
			content = '<tr><th>{:L('收款人')}</th><td>'+data['agent']['name']+'</td></tr><tr><th>{:L('银行名称')}</th><td>'+data['agent']['bank']+'</td></tr><tr><th>{:L('收款方开户行')}</th><td>'+data['agent']['bankprov']+data['agent']['bankcity']+' '+data['agent']['bankaddr']+'</td></tr><tr><th>{:L('收款方账号')}</th><td><span id="invite-copy1">'+data['agent']['bankcard']+'</span><input type="button" value="{:L('复制')}" data-clipboard-action="copy" data-clipboard-target="#invite-copy1" class="copy_button" id="copy_button1"></td></tr><tr><th>{:L('转账金额')}</th><td><b class="red">'+data['order']['num']+'</b></td></tr><tr><th>{:L('转账备注')}</th><td><b class="red" id="invite-copy2">'+data['order']['remarks']+'</b> (请务必填写)<input type="button" value="{:L('复制')}" data-clipboard-action="copy" data-clipboard-target="#invite-copy2" class="copy_button" id="copy_button2"></td></tr><tr><th>{:L('状态')}</th><td>'+data['order']['status']+'</td></tr>';
			
			$("#payment").html(content);
		}
	});
	
    parent.layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: 'autos',
        skin: 'layui-layer-nobg',
        shadeClose: true,
        content: $('#addPayment')
    });
}
function addidcard() {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: 'autos',
        skin: 'layui-layer-nobg',
        shadeClose: true,
        content: $('#addidcard')
    });
}
function addBank() {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: 'autos',
        skin: 'layui-layer-nobg',
        shadeClose: true,
        content: $('#addBank')
    });
}
function closeCharge() {
    layer.closeAll();
	window.location.reload();
}
</script>
<script src="__PUBLIC__/Home/js/clipboard.min.js"></script>
<script>
var clipboard = new Clipboard('#copy_button1');
clipboard.on('success', function(e) {
	layer.msg('{:L('复制成功！')}');
	// console.log(e);
});
clipboard.on('error', function(e) {
	layer.msg('{:L('复制失败！')}');
	console.log(e);
});
	
var clipboard2 = new Clipboard('#copy_button2');
clipboard2.on('success', function(e) {
	layer.msg('{:L('复制成功！')}');
	// console.log(e);
});
clipboard2.on('error', function(e) {
	layer.msg('{:L('复制失败！')}');
	console.log(e);
});
</script>
<include file="Public:footer" />